/**
 * Copyright (c) 2015-2030 by Beijing Yanlight Co., Ltd.
 * All rights reserved.
 */
package com.yanlight.type;

import java.util.Map;
import java.util.TreeMap;

/**
 * 
 * @author haolw
 * @time 2017/08/28
 */
public enum OrderType {
	UNPAID(0, "待付款"),
	PAYMENTED(1,"已支付");
	
	private Integer type;
	private String status;
	private static Integer defaultType = -99;
	private static String defaultStatus = "";

	OrderType(int type, String status) {
		this.type = type;
		this.status = status;
	}
	
	/**
	 * 由状态得到类型
	 * 
	 * @param status
	 * @return
	 */
	public static Integer getTypeByStatus(String status) {
		for (OrderType orderStatusType : OrderType.values()) {
			if (status.equals(orderStatusType.getStatus())) {
				return orderStatusType.getType();
			}
		}
		return defaultType;
	}

	/**
	 * 由类型得到状态
	 * 
	 * @param type
	 * @return
	 */
	public static String getStatusByType(Integer type) {
		for (OrderType orderStatusType : OrderType.values()) {
			if (type.equals(orderStatusType.getType())) {
				return orderStatusType.getStatus();
			}
		}
		return defaultStatus;
	}

	/**
	 * 得到状态类型描述 key:Integer-->类型 , value:String-->状态
	 * 
	 * @return
	 */
	public static Map<Integer, String> getDesc() {
		Map<Integer, String> desc = new TreeMap<Integer, String>();
		for (OrderType orderStatusType : OrderType.values()) {
			desc.put(orderStatusType.getType(), orderStatusType.getStatus());
		}
		return desc;
	}
	
	public Integer getType() {
		return type;
	}

	public void setType(Integer type) {
		this.type = type;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}
}
